import api from '@/utils/request'

// 搜索相关接口类型定义
export interface SearchRequest {
  keyword: string
  advanced?: AdvancedSearchCriteria
  current?: number
  size?: number
  sortField?: string
  sortOrder?: string
}

export interface AdvancedSearchCriteria {
  title?: string
  authors?: string
  abstractText?: string
  keywords?: string
  journal?: string
  startDate?: string
  endDate?: string
  categories?: string[]
}

export interface SearchResultItem {
  id: number
  title: string
  authors: string
  abstractText: string
  keywords: string
  journal: string
  publicationDate: string
  doi: string
  fileName: string
  fileSize: number
  fileType: string
  status: number
  recognitionStatus: number
  uploadUserId: number
  uploadUserName: string
  createTime: string
  updateTime: string
  isFavorite: boolean
  relevanceScore: number
  highlight: HighlightFields
}

export interface HighlightFields {
  title: string
  abstractText: string
  keywords: string
  authors: string
}

export interface PageResult<T> {
  records: T[]
  total: number
  size: number
  current: number
  pages: number
}

// 搜索API
export const searchApi = {
  // 文献搜索
  searchLiterature(data: SearchRequest): Promise<PageResult<SearchResultItem>> {
    return api.post('/search-service/search/literature', data)
  },

  // 获取搜索历史
  getSearchHistory(): Promise<string[]> {
    return api.get('/search-service/search/history')
  },

  // 清除搜索历史
  clearSearchHistory(): Promise<void> {
    return api.delete('/search-service/search/history')
  },

  // 获取热门搜索关键词
  getHotKeywords(): Promise<string[]> {
    return api.get('/search-service/search/hot-keywords')
  }
}